package com.wanxi.repertory.service.utill;

import com.wanxi.repertory.service.api.dto.EnterpriseRepertoryDto;
import com.wanxi.repertory.service.api.dto.ShopRepertoryDto;
import com.wanxi.repertory.service.core_service.RepertoryTotalService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权限校验工具
 */
@Component
public class Check {
    @Resource
    RepertoryTotalService repertoryTotalService;

    /**
     * 查找该sku是否在该商家管理下
     *
     * @param skuId
     * @param enterpriseId
     * @return
     */
    public boolean checkEnterpriseSku(Long enterpriseId, Long skuId) {
        try {
            List<Long> skuIdList = repertoryTotalService.findSkuIdByEnterpriseId(enterpriseId);
            return skuIdList.contains(skuId);
        } catch (NullPointerException e) {
            return false;
        }
    }

    /**
     * 查找该sku是否在该店铺管理下
     *
     * @param shopId
     * @param skuId
     * @return
     */
    public boolean checkShopSku(Long shopId, Long skuId) {
        try {
            ShopRepertoryDto shopRepertoryDto = repertoryTotalService.findShopRepertoryBySkuId(skuId);
            return shopRepertoryDto.getShopId().equals(shopId);
        } catch (NullPointerException e) {
            return false;
        }
    }
}
